<?php
/*
 * @Author: DIYGWCOM 
 * @Date: 2018-05-25 00:58:42 
 * @qq: 287598666 
 * @Last Modified by: DIYGWCOM
 * @Last Modified time: 2018-05-25 01:03:48
 */

 /**
  * 工具类
  */
class DiygwcomUtil{
  public static $DEBUG = false;

  /**
   * 转换移动端url
   * @param  string $url 移动端相对地址/绝对地址
   * @return string      转换后的url
   */
  public static function to_mobile_url($url){
    global $_W;

	return $_W['siteroot'] . 'app' . str_replace('./', '/', $url);
  }
  /**
   * 生成基于MD5随机字符串
   * @param  string $namespace 字符串前缀
   * @return string           随机字符串
   */
  public static function create_guid($namespace = '') {  
	  static $guid = '';
	  $uid = uniqid("", true);
	  $data = $namespace;
	  $data .= $_SERVER['REQUEST_TIME'];
	  $data .= $_SERVER['HTTP_USER_AGENT'];
	  $data .= $_SERVER['LOCAL_ADDR'];
	  $data .= $_SERVER['LOCAL_PORT'];
	  $data .= $_SERVER['REMOTE_ADDR'];
	  $data .= $_SERVER['REMOTE_PORT'];
	  $hash = strtoupper(hash('ripemd128', $uid . $guid . md5($data)));
	  $guid = date('Ymdhis',time()).substr($hash, 0, 8);
	  return $guid;
	 }

}